package com.lry.registy;



import com.lry.common.CommonConstants;
import com.lry.rpc.config.RpcReferenceBean;
import com.lry.rpc.netty.client.ClientCache;

import java.util.List;

import static com.lry.rpc.netty.server.ServerCache.PROVIDER_URL_SET;


public abstract class AbstractRegister implements RegistryService {

    public abstract List<String> getProviderIps(String serviceName,String implName);

    public abstract String getProviderContent(URL url);
    @Override
    public void register(URL url) {
        PROVIDER_URL_SET.add(url);
    }

    @Override
    public void unRegister(URL url) {
        PROVIDER_URL_SET.remove(url);
    }

    @Override
    public void subscribe(URL url) {
        ClientCache.putReferenceBean((RpcReferenceBean) url.getParam().get(CommonConstants.RPC_REFERENCE_BEAN));
    }

    /**
     * 留给子类扩展
     *
     * @param url
     */
    public abstract void doAfterSubscribe(URL url);

    /**
     * 留给子类扩展
     *
     * @param url
     */
    public abstract void doBeforeSubscribe(URL url);


    @Override
    public void unSubscribe(URL url) {
        ClientCache.removeReferenceBean((RpcReferenceBean) url.getParam().get(CommonConstants.RPC_REFERENCE_BEAN));
    }
}
